#include"comm.hpp"

using namespace std;

int main()
{
    int shmid = shmget(ftok(FILE_PATH, NUM), SIZE, IPC_CREAT);
    if(shmid < 0)
    {
        perror("shmget");
        exit(SHMGET_ERR);
    }

    cout << "共享内存创建完毕，shmid：" << shmid << endl;

    char* shmadd = (char*)shmat(shmid, nullptr, 0);

    cout << "挂接完成" << endl;

    while(1)
    {
        if(strlen(shmadd))
        {
            cout << shmadd << endl;
            if(strcmp(shmadd, "exit\n") == 0)
            {
                break;
            }
            sleep(1);
        }
    }

    // sleep(10);

    shmdt(shmadd);

    cout << "去关联成功" << endl;

    return 0;
}